#ifndef __MCU_HARDWARE_I2C_H
#define __MCU_HARDWARE_I2C_H

#include "headfile.h"
#include <stdio.h>

typedef enum
{
    I2C_Mode_Hard,
    I2C_Mode_Soft
} I2C_mode;

class I2C
{
    Software_I2C i2c_soft;
    Hardware_I2C i2c_hard;
    I2C_mode mode;
    int i2c_speed;

public:
    I2C(){};
    I2C(Pin_enum SDA_Pin, Pin_enum SCL_Pin, int speed = 100)
    {
        // Software_I2C i2c = i2c_soft_init(SDA_Pin, SCL_Pin, addr, speed);
        // i2c_soft = i2c;
        i2c_soft.SCL = SCL_Pin;
        i2c_soft.SDA = SDA_Pin;
        i2c_soft.delay_time = 1000000 / (speed * 1000);
        mode = I2C_Mode_Soft;
        i2c_soft.addr=NULL;
    }
    I2C(Hardware_I2C_enum i2c, int speed = 400)
    {
        // i2c_hard = i2c_hard_init(i2c, addr, speed);
        i2c_hard.i2c = i2c;
        i2c_hard.speed = speed;
        mode = I2C_Mode_Hard;
        i2c_hard.addr=NULL;
    }
    ~I2C(){};

public:

    int begin();
    int end();

    uint8_t getDeviceAddr();
    void loadSlave(uint8_t addr);
    void deloadSlave();

    uint8_t check();
    
    size_t write(uint8_t, uint8_t);
    size_t write(uint8_t, const uint8_t *, size_t);
    size_t write(uint8_t, const uint8_t, size_t);
    uint16_t read(uint8_t);
    size_t read(uint8_t, uint8_t *, size_t);
};

#endif
